package com.gali.juc;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Auther: gali
 * @Date: 2022-08-23 15:17
 * @Description:
 */
@Getter
@ToString
@AllArgsConstructor
class User {
    String username;
    int age;
}
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        AtomicReference<User> atomicReference=  new AtomicReference<>();
        User gali = new User("gali", 19);
        User xiaowang = new User("xiaowang", 20);
        atomicReference.set(gali);
        System.out.println(atomicReference.compareAndSet(gali, xiaowang)+"\t"+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(gali, xiaowang)+"\t"+atomicReference.get().toString());
    }
}
